package com.cndongtai.service.firmware;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cndongtai.dao.impl.FirmwareDao;
import com.cndongtai.po.Firmware;
import com.cndongtai.util.DateUtil;
import com.cndongtai.vo.FirmwareBean;

@Service("firmwareService")
public class FirmwareService {
	
	@Resource(name="firmwareDao")
	private FirmwareDao firmwareDao;

	public boolean addFirmware(Firmware firmware) {
		return firmwareDao.addFirmware(firmware);
	}
	
	public boolean deleteFirmware(Firmware firmware) {
		return firmwareDao.deleteFirmware(firmware);
	}
	
	public Firmware queryFirmwareById(Long id) {
		return firmwareDao.queryFirmwareById(id);
	}
	
	public List<FirmwareBean> queryFirmwareList() {
		List<Firmware> firmwareList = firmwareDao.queryFirmwareList();
		return convertFirmware(firmwareList);
	}
	
	private List<FirmwareBean> convertFirmware(List<Firmware> firmwareList) {
		List<FirmwareBean> firmwareBeanList = new ArrayList<FirmwareBean>();
		if(firmwareList==null) {
			return firmwareBeanList;
		}
		
		for(int i=0;i<firmwareList.size();i++) {
			
			Firmware firmware = firmwareList.get(i);
			FirmwareBean firmwareBean = new FirmwareBean();
			firmwareBean.setId(firmware.getId());
			firmwareBean.setFirmwareName(firmware.getFirmwareName());
			firmwareBean.setProtocalVersion(firmware.getProtocalVersion());
			firmwareBean.setHardwareVersion(firmware.getHardwareVersion());
			firmwareBean.setFirmwareVersion(firmware.getFirmwareVersion());
			firmwareBean.setDescription(firmware.getDescription());
			firmwareBean.setCreateTime(DateUtil.timeFormat(firmware.getCreateTime()));
			
			firmwareBeanList.add(firmwareBean);
		}
		
		return firmwareBeanList;
	}
}
